package net.lb.socketserver.handler.impl;

import java.nio.charset.Charset;
import javax.annotation.Resource;
import net.lb.baseutil.collection.ByteCache;
import net.lb.socketserver.bus.BusinessCommand;
import net.lb.socketserver.bus.Message;
import net.lb.socketserver.handler.MessageHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Resource
public class Utf8EchoHandler implements MessageHandler
{
    private Logger  logger  = LogManager.getLogger();
    private Charset charset = Charset.forName("utf-8");
    
    @Override
    public byte interestedDataPacketType()
    {
        return BusinessCommand.ECHO;
    }
    
    @Override
    public void handler(Message message)
    {
        ByteCache cache = message.getBusinessData();
        logger.trace("收到的消息是{},消息长度{}", cache.toString(charset), cache.startRead(0).remaining());
        message.setResult(true);
    }
}
